home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / ctlib100.zip / INSTALL.LZH / ARRAYSH2.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-12  |  3KB  |  109 lines

  1. {**************************************************************************}
  2. {*  BitSoft Development, L.L.C.                                           *}
  3. {*  Copyright (C) 1995, 1996 BitSoft Development, L.L.C.                  *}
  4. {*  All rights reserved.                                                  *}
  5. {*  Containers Library demo                                               *}
  6. {**************************************************************************}
  7.  
  8. program ArraysHuge2;
  9.  
  10. {$X+}
  11.  
  12. { Sample program for accesing directly a huge array }
  13.  
  14. uses Containr, ctArrays,
  15.      {$ifdef Windows}
  16.      WinCtr;
  17.      {$else}
  18.      Crt;
  19.      {$endif}
  20.  
  21. type
  22.   PWeatherInfo = ^TWeatherInfo;
  23.   TWeatherInfo = record
  24.     Location : string[20];
  25.     Humidity : Integer;
  26.     Rain : Integer;
  27.   end; { TWeatherInfo }
  28.  
  29. procedure DisplayWeatherData(WeatherData : PSequence);
  30. var
  31.   i : Integer;
  32. begin
  33.   with WeatherData^ do
  34.     for i := FirstIndex to LastIndex do
  35.       with PWeatherInfo(At(i))^ do
  36.         writeln('Hour: ', i:2, ':00', '':3, Location, '':20 -
  37.           Length(Location), Humidity, '':5, Rain:5);
  38. end;
  39.  
  40. procedure FindLowHumidityValue(WeatherData : PSequence);
  41. var
  42.   Item : Pointer;
  43.   Index : LongInt;
  44.  
  45.   function HasLowHumidity(Item : PWeatherInfo) : Boolean; far;
  46.   begin
  47.     HasLowHumidity := (Item^.Humidity < 22);
  48.   end;
  49.  
  50. begin
  51.   Item := WeatherData^.FirstThat(@HasLowHumidity, Index);
  52.   writeln ('First with low humidity (H < 22):');
  53.   with PWeatherInfo(Item)^ do
  54.     writeln('Hour: ', Index:2, ':00', '':3, Location, '':20 -
  55.       Length(Location), Humidity, '':5, Rain:5);
  56. end;
  57.  
  58. var
  59.   MorningWeatherData : PHugeArray;
  60.   WeatherInfo: TWeatherInfo;
  61.  
  62. begin
  63.   ClrScr;
  64.  
  65.   { Create the array }
  66.   MorningWeatherData := New(PHugeArray, Init(7, 11, SizeOf(TWeatherInfo)));
  67.  
  68.   { Insert the items in the array }
  69.   with MorningWeatherData^ do
  70.   begin
  71.     with PWeatherInfo(At(7))^ do
  72.     begin
  73.       Location := 'Miami';
  74.       Humidity := 34;
  75.       Rain := 0;
  76.     end;
  77.     with PWeatherInfo(At(8))^ do
  78.     begin
  79.       Location := 'Helsinski';
  80.       Humidity := 23;
  81.       Rain := 3;
  82.     end;
  83.     with PWeatherInfo(At(9))^ do
  84.     begin
  85.       Location := 'Canada';
  86.       Humidity := 26;
  87.       Rain := 2;
  88.     end;
  89.     with PWeatherInfo(At(10))^ do
  90.     begin
  91.       Location := 'Berlin';
  92.       Humidity := 28;
  93.       Rain := 5;
  94.     end;
  95.     with PWeatherInfo(At(11))^ do
  96.     begin
  97.       Location := 'Melbourne';
  98.       Humidity := 20;
  99.       Rain := 0;
  100.     end;
  101.   end; { with }
  102.  
  103.   DisplayWeatherData(MorningWeatherData);
  104.   writeln;
  105.   FindLowHumidityValue(MorningWeatherData);
  106.  
  107.   { Dispose of the array }
  108.   Dispose(MorningWeatherData, Done);
  109. end.